import { dialogFunc } from './core.js';
import "../css/dialog.css";
import { clientUtil } from './util'
var loading_dia={
    counter:0,
    dia:null
};
// var JoyDialog = function(options){
//    return dialogFunc(options)
// }
// JoyDialog.showLoading = function(msg){
    
// }
// JoyDialog.hideLoading = function(){
    
// }
// JoyDialog.clientObject = JSON.parse(JSON.stringify(clientUtil(window)))

// export function { JoyDialog }
function init(f){   
    f.showLoading = function(msg){
        if(loading_dia.counter<0){
            loading_dia.counter=0;
        }
        loading_dia.counter++;
        if(!loading_dia.dia){
            var jdia=JoyDialog({
                type : 'loading',
                infoText: msg??'',
                autoClose:0
            });
            loading_dia.dia = jdia;
        }else{
            loading_dia.dia.update({infoText: msg??''})
        }
    }
    f.hideLoading = function(){
        loading_dia.counter--;
        if(loading_dia.dia&&loading_dia.counter<=0){
            loading_dia.dia.close();
            loading_dia.dia = null;        
        }
    }
    f.clientObject = JSON.parse(JSON.stringify(clientUtil(window)))
    return f;
}
var  JoyDialog  = init(dialogFunc)
export {JoyDialog}
